package com.jeesite.modules.task.status.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.task.status.entity.DcSupTaskStatus;
import com.jeesite.modules.task.status.service.DcSupTaskStatusService;

/**
 * 任务状态变更表Controller
 * @author zrr
 * @version 2022-03-02
 */
@Controller
@RequestMapping(value = "${adminPath}/status/dcSupTaskStatus")
public class DcSupTaskStatusController extends BaseController {

	@Autowired
	private DcSupTaskStatusService dcSupTaskStatusService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DcSupTaskStatus get(String id, boolean isNewRecord) {
		return dcSupTaskStatusService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequestMapping(value = {"list", ""})
	public String list(DcSupTaskStatus dcSupTaskStatus, Model model) {
		model.addAttribute("dcSupTaskStatus", dcSupTaskStatus);
		return "modules/task/status/dcSupTaskStatusList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DcSupTaskStatus> listData(DcSupTaskStatus dcSupTaskStatus, HttpServletRequest request, HttpServletResponse response) {
		dcSupTaskStatus.setPage(new Page<>(request, response));
		String org = dcSupTaskStatus.getRemarks4();
		dcSupTaskStatus.setRemarks4(null);
		Page<DcSupTaskStatus> page = dcSupTaskStatusService.findPage(dcSupTaskStatus);
		page.getList().forEach(
				p-> {p.setRemarks4(org);}
		);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("status:dcSupTaskStatus:view")
	@RequestMapping(value = "form")
	public String form(DcSupTaskStatus dcSupTaskStatus, Model model) {
		model.addAttribute("dcSupTaskStatus", dcSupTaskStatus);
		return "modules/task/status/dcSupTaskStatusForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("status:dcSupTaskStatus:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DcSupTaskStatus dcSupTaskStatus) {
		dcSupTaskStatusService.save(dcSupTaskStatus);
		return renderResult(Global.TRUE, text("保存任务状态变更信息成功！"));
	}
	
	/**
	 * 停用数据
	 */
	@RequiresPermissions("status:dcSupTaskStatus:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(DcSupTaskStatus dcSupTaskStatus) {
		dcSupTaskStatus.setStatus(DcSupTaskStatus.STATUS_DISABLE);
		dcSupTaskStatusService.updateStatus(dcSupTaskStatus);
		return renderResult(Global.TRUE, text("停用任务状态变更信息成功"));
	}
	
	/**
	 * 启用数据
	 */
	@RequiresPermissions("status:dcSupTaskStatus:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(DcSupTaskStatus dcSupTaskStatus) {
		dcSupTaskStatus.setStatus(DcSupTaskStatus.STATUS_NORMAL);
		dcSupTaskStatusService.updateStatus(dcSupTaskStatus);
		return renderResult(Global.TRUE, text("启用任务状态变更信息成功"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("status:dcSupTaskStatus:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DcSupTaskStatus dcSupTaskStatus) {
		dcSupTaskStatusService.delete(dcSupTaskStatus);
		return renderResult(Global.TRUE, text("删除任务状态变更信息成功！"));
	}
	
}